var express = require('express');
var router = express.Router();
const { toiletModel, problemModel, opinionModel } = require('../models/model')

/* GET home page. */
// router.get('/', function(req, res, next) {
//   res.render('index', { title: 'Express' });
// });

router.get('/getToiletInfo', async (req,res) => {
  const data=await toiletModel.find()
  console.log(data);
  res.send({
    code: 200,
    data
  })
})

router.get('/getProblemInfo', async (req,res) => {
  let {page,pageSize}=req.query
  const data=await problemModel.find().skip((page-1)*pageSize).limit(pageSize)
  let len=await problemModel.find()
  len=len.length
  res.send({
    code: 200,
    data,
    len
  })
})

router.get('/getOpinionInfo', async (req,res) => {
  let {page,pageSize}=req.query
  const data=await opinionModel.find().skip((page-1)*pageSize).limit(pageSize)
  let len=await opinionModel.find()
  len=len.length
  res.send({
    code: 200,
    data,
    len
  })
})

module.exports = router;
